package com.chat.admin.controller;

import com.chat.admin.domain.DTO.LoginAdminDTO;
import com.chat.admin.domain.DTO.RefreshTokenDTO;
import com.chat.admin.domain.VO.LoginAdminVO;
import com.chat.admin.domain.VO.RefreshTokenVO;
import com.chat.admin.service.LoginService;
import com.chat.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理员登录模块
 */
@RestController
@Validated
@RequestMapping("/admin")
public class LoginController {

    @Autowired
    LoginService loginService;
    /**
     * 用户登录
     */
    @PostMapping("/login")
    public R<LoginAdminVO> login(@Validated @RequestBody LoginAdminDTO loginAdminDTO){
        return loginService.login(loginAdminDTO);
    }

    /**
     * 刷新路由
     * @param refreshToken
     * @return
     */
    @PostMapping("/refreshToken")
    public R<RefreshTokenVO> refreshToken(@Validated @RequestBody RefreshTokenDTO refreshToken){
        return loginService.refreshToken(refreshToken);
    }
}
